import java.io.*;
import java.util.Random;

public abstract class MyTools
{
    static public String getExceptionString(Exception ex)
    {
        StringWriter stringWriter=new StringWriter();
        PrintWriter printWriter=new PrintWriter(stringWriter);
        ex.printStackTrace(printWriter);
        return stringWriter.toString();
    }

    static public void printExceptionString(Exception ex)
    {
        System.out.println(getExceptionString(ex));
    }

    static public String getRandomString(int length)
    {
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++)
        {
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    static public boolean equals(String filename1,String filename2)
    {
        try
        {
            InputStream inputStream1=new FileInputStream(filename1);
            InputStream inputStream2=new FileInputStream(filename2);
            while(true)
            {
                int tmp1=inputStream1.read();
                int tmp2=inputStream2.read();
                if(tmp1!=tmp2)
                    return false;
                if(tmp1==-1)
                    break;
            }
            inputStream2.close();
            inputStream1.close();
        }catch(IOException e)
        {
//            e.printStackTrace();
            return false;
        }
        return true;
    }

    static public void copy(String filename1,String filename2) throws IOException
    {
        InputStream inputStream=new FileInputStream(filename1);
        OutputStream outputStream=new FileOutputStream(filename2);
        for(int tmp=0;(tmp=inputStream.read())!=-1;outputStream.write(tmp)) ;
        outputStream.close();
        inputStream.close();
    }
}
